import * as puppeteer from 'puppeteer';

async function login()
{
    const browser = await puppeteer.launch({ headless: false });//创建一个browser浏览器实例对象
    const page = await browser.newPage();//创建一个浏览器页面page对象
    await page.goto('https://juejin.im');//打开网页地址

    const login = await page.$('#juejin > div.view-container > div > header > div > nav > ul > li.nav-item.auth > span.login'); //定义登录元素
    await login.click();//点击登录

    await page.type("[name=loginPhoneOrEmail]",'xxxxx', { delay: 20 });//输入用户名
    await page.type("[placeholder=请输入密码]",'xxxx', { delay: 20 });//输入密码

    const authLogin = await page.$('.panel .btn');//定义登录按钮元素
    await authLogin.click();//点击登录

    await page.waitFor(1000);

    let str = await page.$eval(".content",el=>el.textContent);
    console.log(str);
    //await page.screenshot({path: 'screenshots/sf-juejin/login.png', type: 'png'});//进行截图保存路径
    // browser.close();//关闭浏览器
}
login();
